package com.zhiyun.utils;

import com.thoughtworks.qdox.model.JavaClass;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class CacheUtil {

    public static final String ALL_CLASSES = "all";

    private static ConcurrentHashMap<String,List<JavaClass>> cache = new ConcurrentHashMap<>();


    public static void put(String key, List<JavaClass> classes){
        cache.put(key,classes);
    }

    public static List<JavaClass> get(String key){
       return cache.get(key);
    }

    public static Map<String,JavaClass> toMap(String key){
        List<JavaClass> javaClasses = cache.get(key);
        return javaClasses.stream().collect(Collectors.toMap(JavaClass::getFullyQualifiedName, s -> s));
    }
}
